# encoding=utf-8

from com.utls.pro_env import *
from xml.etree.ElementTree import *

def resolve_conf(dt):
    conf_file = PROJECT_CONF_DIR + "Export.xml"

    xml_tree = ElementTree.parse(conf_file)
    tasks = xml_tree.findall('./table')

    for task in tasks:
        tables = task.findall("./table")
        cmds = []
        for i in range(len(tables)):
            table_name = tables[i].text
            table_conf_file = PROJECT_CONF_DIR + table_name + ".xml"
            xmlTree = ElementTree.parse(table_conf_file)
            sqoopNodes = xmlTree.findall("./sqoop-shell")
            sqoop_cmd_type = sqoopNodes[0].attrib['type']
            praNodes = sqoopNodes[0].findall("./param")
            cmap = {}
            for i in range(len(praNodes)):
                key = praNodes[i].attrib["key"]
                value = praNodes[i].text
                cmap[key] = value

                command = "sqoop " + "--" + sqoop_cmd_type

                for key in cmap.keys():
                    value = cmap[key]

                    if(value == None or value == "" or value == " "):
                        value = ""

                    command += " --" + key + " " + value + "\n"
            cmds.append(command)

        return cmds